package ru.acme.lab11;

import ru.acme.lab11.domain.account.CheckingAccount;
import ru.acme.lab11.domain.account.SavingAccount;
import ru.acme.lab11.domain.bank.Bank;
import ru.acme.lab11.domain.client.Client;
import ru.acme.lab11.domain.client.Gender;
import ru.acme.lab11.exceptions.ClientExistsException;
import ru.acme.lab11.exceptions.NotEnoughFundsException;
import ru.acme.lab11.service.bank.BankService;

public class BankApplication {

	private static final String[] names = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
	private static final Gender[] genders = { Gender.MALE, Gender.MALE,
			Gender.FEMALE, Gender.FEMALE, Gender.MALE, Gender.MALE,
			Gender.FEMALE, Gender.FEMALE, Gender.MALE, Gender.MALE };

	public static void main(String[] argv) {
		Bank bank = new Bank();

		for (int i = 0; i < names.length / 2; ++i) {
			try {
				BankService.addClient(bank, new Client(names[i], genders[i], new SavingAccount(30)));
			} catch (ClientExistsException e) {
				System.out.println("Client exists");;
			}
		}
		for (int i = names.length / 2; i < names.length; ++i) {
			try {
				BankService.addClient(bank, new Client(names[i], genders[i], new CheckingAccount(30, 20)));
			} catch (ClientExistsException e) {
				System.out.println("Client exists");;
			}
		}

		BankService.printBalances(bank);
		BankService.printMaximumAmountsToWithdraw(bank);
		try {
			BankService.modifyBank(bank);
		} catch (NotEnoughFundsException e) {
			System.out.println("Somebody has balance " + e.getAccount().getBalance() + ", max withdraw " + e.getAccount().getMaxWithdraw() + ", and need additional credit " + e.getAmount());
		}
		BankService.printBalances(bank);
		BankService.printMaximumAmountsToWithdraw(bank);
	}

}
